/*
 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __configs_chromeos_tegra2_developer_h__
#define __configs_chromeos_tegra2_developer_h__

#include <configs/chromeos/developer.h>
#include <configs/chromeos/tegra2/common.h>

#include <configs/chromeos/tegra2/parts/nand.h>
#include <configs/chromeos/tegra2/parts/usb.h>

/*
 * We expect all Tegra2 machines to have SPI flash as defined by the
 * firmware_layout.h config file. The environment will go there.
 */
#define CONFIG_ENV_IS_IN_SPI_FLASH 1

#define CONFIG_ENV_SECT_SIZE    CONFIG_LENGTH_ENV
#define CONFIG_ENV_OFFSET       CONFIG_OFFSET_ENV

/* Override the environment size, since we only need a small area */
#undef CONFIG_ENV_SIZE
#define CONFIG_ENV_SIZE         CONFIG_LENGTH_ENV

#define CONFIG_SYS_MEMTEST_START       0x0000
#define CONFIG_SYS_MEMTEST_END         0x1000

/*
 * Developer-friendly booting options:
 *
 * dhcp_boot: get IP address from DHCP, download kernel from TFTP, then boot
 *            with NFS root.
 * netroot_boot: get IP address from DHCP, download kernel and rootfs from
 *               TFTP, then boot.
 * keynfs_boot: get kernel from USB stick ext2 partition 1, then NFS root.
 *              NOTE: not in the boot command by default.
 * usb_boot: boot from a USB image made with image_to_usb.sh.
 * mmc1_boot: boot from an SD card made with image_to_usb.sh.
 * mmc0_boot: boot from an image installed in eMMC.
 *
 * regen_all sets up the bootargs, so must be run after any change to
 * environment variables.
 *
 * The network adapter must be available before starting an dhcp_boot. You
 * may need to use 'usb start' first if you are using a USB ethernet adapter.
 * The same applies for usb_boot.
 */

#define CONFIG_EXTRA_ENV_SETTINGS_ARCH \
	"console=ttyS0,115200n8\0"\
	"cros_bootfile=/boot/vmlinux.uimg\0"\
	"user=user\0"\
	"board=arm\0"\
	"serial#=1\0"\
	"tftpkernelpath=/tftpboot/uImage\0"\
	"tftprootpath=/tftpboot/initrd\0"\
	"tftpserverip=0.0.0.0\0"\
	"nfsserverip=0.0.0.0\0"\
	"rootaddr=0x12008000\0"\
	"setup_shared_mem="\
		"setenv bypass_load_kernel 1; "\
		"cros load_k 1 2\0"\
	"regen_all="\
		"setenv common_bootargs console=${console} "\
		"${platform_extras}; "\
		"setenv bootargs ${common_bootargs} ${extra_bootargs} "\
		"${bootdev_bootargs}\0"\
	"regen_nfsroot_bootargs=setenv bootdev_bootargs "\
			"dev=/dev/nfs4 rw nfsroot=${nfsserverip}:${rootpath} "\
			"ip=dhcp noinitrd; "\
		"run regen_all\0"\
	"regen_initrdroot_bootargs=setenv bootdev_bootargs "\
			"rw root=/dev/ram0 ramdisk_size=294912; "\
		"run regen_all\0"\
	\
	"dhcp_setup=setenv tftpkernelpath "\
			"/tftpboot/uImage-${user}-${board}-${serial#}; "\
		"setenv tftprootpath "\
			"/tftpboot/initrd-${user}-${board}-${serial#}; "\
		"setenv rootpath " CONFIG_ROOTPATH "; "\
		"setenv autoload n\0"\
	"dhcp_boot=run dhcp_setup; "\
		"run regen_nfsroot_bootargs; "\
		"bootp; "\
		"if tftpboot ${loadaddr} ${tftpserverip}:${tftpkernelpath}; "\
		"then "\
			"run setup_shared_mem; "\
			"bootm ${loadaddr}; "\
		"fi\0"\
	"netroot_boot=run dhcp_setup; "\
		"run regen_initrdroot_bootargs; "\
		"bootp; "\
		"if tftpboot ${rootaddr} ${tftpserverip}:${tftprootpath} && "\
		"   tftpboot ${loadaddr} ${tftpserverip}:${tftpkernelpath}; "\
		"then "\
			"run setup_shared_mem; "\
			"bootm ${loadaddr} ${rootaddr}; "\
		"fi\0"\
	\
	"ext2_boot=setenv bootdev_bootargs root=/dev/${devname}3 rootwait ro; "\
		"run regen_all; "\
		"if ext2load ${devtype} ${devnum}:3 "\
		            "${loadaddr} ${cros_bootfile}; then "\
			"run setup_shared_mem; "\
			"bootm ${loadaddr};" \
		"fi\0" \
	\
	"keynfs_setup="\
		"setenv rootpath " CONFIG_ROOTPATH "; "\
		"run regen_nfsroot_bootargs\0" \
	"keynfs_boot=run keynfs_setup; "\
		"if ext2load usb 0:1 ${loadaddr} uImage; then "\
			"run setup_shared_mem; "\
			"bootm ${loadaddr};" \
		"fi\0" \
	\
	"usb_boot=setenv devtype usb; "\
		"setenv devnum 0; "\
		"setenv devname sda; "\
		"run ext2_boot\0" \
	\
	"net_boot=if test ${tftpserverip} != \"0.0.0.0\"; then "\
			"if test ${ethact} != \"\"; then " \
				"run netroot_boot ; " \
				"run dhcp_boot ; " \
			"fi ; " \
		"fi\0" \
	\
	"mmc_boot=mmc init ${devnum}; "\
		"setenv devtype mmc; "\
		"setenv devname mmcblk${devnum}p; "\
		"run ext2_boot\0"\
	"mmc0_boot=setenv devnum 0; "\
		"run mmc_boot\0"\
	"mmc1_boot=setenv devnum 1; "\
		"run mmc_boot\0"

/*
 * Our developer-friendly boot process tries a number of things in sequence
 * until it finds a kernel. Network booting is tried first if we have Ethernet.
 *
 * NOTE: we purposely only issue a 'usb start' once per USB port to avoid
 * <http://crosbug.com/15206>.  This has the side effect that a USB stick on
 * usb 0 will override a network adapter on usb 1.  For now, we'll have to
 * live with that.
 */
#define CONFIG_BOOTCOMMAND "cros_developer_firmware"


#endif /* __configs_chromeos_tegra2_developer_h__ */
